import torch
import torch.nn as nn
from torch.utils.tensorboard import SummaryWriter
import torchvision

class Module(nn.Module):
    def __init__(self):
        super(Module,self).__init__()
        self.conv1 = nn.Conv2d(in_channels=3,out_channels=32,kernel_size=(5,5),padding=2)
        self.pool1 = nn.MaxPool2d(kernel_size=2)
        self.conv2 = nn.Conv2d(in_channels=32,out_channels=32,kernel_size=(5,5),padding=2)
        self.pool2 = nn.MaxPool2d(kernel_size=(2,2))
        self.conv3 = nn.Conv2d(in_channels=32,out_channels=64,kernel_size=(5,5),padding=2)
        self.pool3 = nn.MaxPool2d(kernel_size=(2,2))
        self.flatten = nn.Flatten()
        self.linear1 = nn.Linear(1024,64)
        self.linear2 = nn.Linear(64,10)
    def forward(self,x):
        #可以使用sequenti方法组成相关模型,简化代码
        x = self.conv1(x)
        x = self.pool1(x)
        x = self.conv2(x)
        x = self.pool2(x)
        x = self.conv3(x)
        x = self.pool3(x)
        x = self.flatten(x)
        x = self.linear1(x)
        x = self.linear2(x)
        return x


writer = SummaryWriter("log5")
MyModule = Module()
n1 = torch.ones([64,3,32,32])
n2 = MyModule(n1)
print(n2.shape)
writer.add_graph(MyModule,n1)
writer.close()



